import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-detail',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.scss']
})
export class DetailComponent implements OnInit {
  id: any;
  type: any;
  title: any;
  titleList: any;
  message: any = {
    '_id': ''
  };


  constructor(private http: HttpClient, private route: ActivatedRoute) { }
  getMessage() {

  }
  /**
   * @description 返回
   */
  goBack() {
    window.history.go(-1);
  }

  ngOnInit() {
    this.id = this.route.snapshot.params['id'];
    this.type = this.route.snapshot.params['type'];
    if (this.type === '中药饮片') {
      this.titleList = ['别名', '汉语拼音', '英文名', '药材基原', '动植物形态', '资源分布', '生态环境', '药用植物栽培', '采收和储藏', '药用部位', '生药材鉴定', '中药化学成分', '理化性质', '中药化学鉴定', '中药有效成分结构式的测定', '炮制方法', '剂型', '中药制药工艺', '药理作用', '药理学', '药代动力学', '毒理学', '药物配伍', '药性', '归经', '功效', '功效分类', '主治', '用法用量', '用药禁忌', '不良反应及治疗', '选方', '临床运用', '各家论述', '考证', '药物应用鉴别', '药典收录', '药材拉丁名', '拉丁植物动物矿物名', '科属分类', '出处'];
      this.http.get(window.API_ROOT + 'api/data/zyyps/' + this.id).toPromise().then((res: any) => {
        this.title = res.data.ym;
        this.message = res.data;
      });
    } else if (this.type === '中成药') {
      this.titleList = ['组成', '用法', '类型1', '类型2', '类型3'];
      this.http.get(window.API_ROOT + 'api/data/zcys/' + this.id).toPromise().then((res: any) => {
        this.title = res.data['药名'];
        this.message = res.data;
      });
    } else if (this.type === '经典方') {
      this.titleList = ['处方来源', '药物组成', '加减', '功效', '主治', '制备方法', '用法用量', '用药禁忌', '临床应用', '药理作用', '各家论述', '备注'];
      this.http.get(window.API_ROOT + 'api/data/jdfs/' + this.id).toPromise().then((res: any) => {
        this.title = res.data['方剂名称'];
        this.message = res.data;
      });
    } else if (this.type === '协定方') {
      this.titleList = ['组成', '类型'];
      this.http.get(window.API_ROOT + 'api/data/xdfs/' + this.id).toPromise().then((res: any) => {
        this.title = res.data['方名'];
        this.message = res.data;
      });

    }
  }
}
